//
//  WmcSettingSubTitleActionSwitchItemCell.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/7/24.
//

import UIKit

class WmcSettingSubTitleActionSwitchItemCell: WmcSettingSubTitleSwitchItemCell {

    private lazy var actionButton: UIButton = {
        let button = UIButton()
        return button
    }()
    
    override func makeUI() {
        super.makeUI()
        // stackView
        stackView.snp.remakeConstraints { make in
            make.left.equalTo(Wmc_standardEdge.left)
            make.centerY.equalToSuperview()
        }
        // imageView
        addSubview(actionButton)
        actionButton.snp.makeConstraints { make in
            make.left.equalTo(stackView.snp.right).offset(8.0.wmc_autoHor)
            make.centerY.equalToSuperview()
            make.size.equalTo(0.0)
            make.right.lessThanOrEqualTo(switchBtn.snp.left).offset(-8.0.wmc_autoHor)
        }
        // 红点
        redPointView.snp.remakeConstraints { make in
            make.top.right.equalTo(actionButton)
            make.size.equalTo(pointSize)
        }
        
    }
    
    override func bindEvent() {
        super.bindEvent()
        actionButton.rx.tap.subscribe(onNext: {
            [weak self] in
            guard let self = self else { return }
            guard let switchItem = self.item as? WmcSettingSubTitleActionSwitchItem else { return }
            switchItem.buttonAction?(switchItem)
        }).disposed(by: rx.disposeBag)
    }
    
    override func didSetItem() {
        super.didSetItem()
        let switchItem = (item as? WmcSettingSubTitleActionSwitchItem) ?? .init()
        actionButton.setImage(switchItem.image, for: .normal)
        actionButton.snp.updateConstraints { make in
            make.size.equalTo(switchItem.buttonSize)
        }
    }
}
